const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
// 新版本的写法
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
    entry: "./src/main.js",
    module: {
        rules: [
            {
                test: /\.(png|svg|jpg|gif|jpeg|ico|woff|woff2|eot|ttf|otf)$/,
                use: [
                    {
                        // 根据图片大小，把图片优化成base64
                        loader: 'url-loader',
                        options: {
                            // 10kb
                            limit: 30000
                        }
                    },
                    {
                        loader: 'image-webpack-loader',
                        options: {
                            mozjpeg: {
                                progressive: true,
                                quality: 65
                            },
                            optipng: {
                                enabled: false,
                            },
                            pngquant: {
                                quality: '65-90',
                                speed: 4
                            },
                            gifsicle: {
                                interlaced: false,
                            },
                            webp: {
                                quality: 75
                            }
                        }
                    }
                ]
            }]
    },
    plugins: [
        // html打包插件
        new HtmlWebpackPlugin({
            title: 'AICODER 全栈线下实习', // 默认值：Webpack App
            filename: 'index.html', // 默认值： 'main.html'
            template: path.resolve(__dirname, 'src/main.html'),
            minify: {
                // collapseWhitespace: true,
                // removeComments: true, // 是否移除注释
                // removeAttributeQuotes: true // 移除属性的引号
            }
        }),
        // 自动清理dist文件夹
        new CleanWebpackPlugin()
    ]
};